package com.party.mobile.biz.analysis;

import com.party.core.model.analysis.StatisticsUserVisit;
import com.party.core.service.analysis.IStatisticsUserVisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @program: Project
 * @description: 用户访问_业务接口实现
 * @author: Huaqunhao
 * @create: 2018-08-08 14:41
 **/
@Service
public class StatisticsUserVisitBizService {
    @Autowired
    private IStatisticsUserVisitService statisticsUserVisitService;

    public  void insert(String sign) throws Exception{
       // _____———____这里有线程安全问题!!!!!!!!!!

        StatisticsUserVisit suv = new StatisticsUserVisit();
        suv.setCreateDate(new Date());
        StatisticsUserVisit svndb = statisticsUserVisitService.getBycreateDate(suv);
        //如果当天没有记录
        if (svndb == null) {
            svndb = statisticsUserVisitService.get(statisticsUserVisitService.insert(suv));
        }
        //新的
        if("new".equalsIgnoreCase(sign)){
            Integer newNumCount = svndb.getNewNum();

            if(newNumCount==null||newNumCount==0){
                newNumCount = 1;
            }else{
                newNumCount = svndb.getNewNum()+1;
            }

            svndb.setNewNum(newNumCount);
        }
        //旧的
        if("old".equalsIgnoreCase(sign)){
            svndb.setOldNum(svndb.getOldNum()+1);
        }
        statisticsUserVisitService.update(svndb);
    }
}
